package com.tangkun.environment.fragment;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.tangkun.environment.network.NetworkUtil;
import com.tangkun.environment.rx.RxFragment;
import com.umeng.analytics.MobclickAgent;

import retrofit.Retrofit;

/**
 * BaseFragment[v 1.0.0]
 * classes:com.yixin.oaoinventory.base.BaseFragment
 *
 * @author lileiyi
 * @date 2016/3/16
 * @time 9:41
 * @description
 */
public class BaseFragment extends RxFragment {

    protected Retrofit retrofit;
    protected NetworkUtil.FromNetwork fromNetwork;
    /**
     * 每页20条 （以后要该分页条数在这里改）
     */
    protected int pageSize = 20;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        retrofit = NetworkUtil.getRetrofit();
        fromNetwork = retrofit.create(NetworkUtil.FromNetwork.class);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(getActivity());
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(getActivity());
    }

    private Toast mToast;

    /**
     * showToast
     *
     * @param msg
     */
    public void showToast(String msg) {
        if (mToast == null) {
            mToast = Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT);
            mToast.setGravity(Gravity.CENTER, 0, 0);//居中显示
        } else {
            mToast.setText(msg);
            mToast.setGravity(Gravity.CENTER, 0, 0);//居中显示
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public void cancelToast() {
        if (mToast != null) {
            mToast.cancel();
        }
    }

}
